#!/bin/bash
set -e

PYTHON=python
REPO=$(dirname $(dirname $(realpath $0)))

echo "Running Package Deployment ${REPO}"
echo "=============================================================="

echo "Preparing Virtual Environment"
echo "----------------------------------"
cd $REPO
rm -rf ./dist
mkdir dist
$PYTHON -m venv ./dist/venv
source ./dist/venv/bin/activate
python3 -m pip install $REPO
python3 -m pip install pyinstaller pillow

echo "Create Pyinstaller Distribution"
echo "----------------------------------"
pyinstaller fusionmatrix/__main__.py \
    -n FusionMatrix -D \
    -i fusionmatrix/assets/images/fusionmatrix.png \
    --add-data fusionmatrix/assets/images/*:assets/images \
    --windowed \
    --noconfirm --clean \
    --distpath dist

if [[ "$INNOSETUP" == "1" ]]; then
    echo "Creating Innosetup Installer"
    echo "----------------------------------"
    powershell "iscc ./scripts/innosetup.iss /DDISTPATH=../dist/FusionMatrix/ /O./dist/"
fi

echo "All done, have fun ;)"